package newfragment;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.dell.avtivity.R;

import java.util.ArrayList;
import java.util.List;

import Adapter.FragmentAdapter;

/**
 * Created by dell on 2017/1/26.
 */

public class SignInMain extends Fragment {
    private TabLayout tablayout;
    private ViewPager viewpager;
    private FragmentPagerAdapter adapter;
    private List<Fragment> content;
    private List<String> title;
    private View view;
    private LoginFragment login;
    private PhoneInfragment phoneInfragment;
    private FragmentManager fm;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.all, container, false);
        fm=getChildFragmentManager();
        init(view);
        return view;
    }

    private void init(View view) {
        tablayout = (TabLayout) view.findViewById(R.id.title_tabs);
        viewpager = (ViewPager) view.findViewById(R.id.viewpager);

        login = new LoginFragment();
        phoneInfragment = new PhoneInfragment();

        //FragmentList
        content = new ArrayList<Fragment>();
        content.add(login);
        content.add(phoneInfragment);

        //TitleList
        title = new ArrayList<String>();
        title.add("账号登录");
        title.add("手机登录");


        tablayout.setTabMode(TabLayout.MODE_FIXED);
        tablayout.addTab(tablayout.newTab().setText(title.get(0)));
        tablayout.addTab(tablayout.newTab().setText(title.get(1)));

        //Adapter
        adapter = new FragmentAdapter(fm, content, title);
        viewpager.setAdapter(adapter);
        tablayout.setupWithViewPager(viewpager);

    }

}

